<html>
<head>
    <title>Utilty.java</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <style type="text/css">
        .ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
        .s0 { color: rgb(0,0,128); font-weight: bold; }
        .s1 { }
        .s2 { color: rgb(128,128,128); font-style: italic; }
        .s3 { color: rgb(0,128,0); font-weight: bold; }
        .s4 { color: rgb(0,0,255); }
    </style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#C0C0C0">
    <TR>
        <TD>
            <CENTER>
                <FONT FACE="Arial, Helvetica" COLOR="#000000">
                    Utilty.java</FONT>
            </center>
        </TD>
    </TR>
</TABLE>
<pre>

<a name="l1"><span class="ln">1    </span></a><span class="s0">package </span><span class="s1">com.ibr.ticketmanagement.app.util; 
<a name="l2"><span class="ln">2    </span></a> 
<a name="l3"><span class="ln">3    </span></a></span><span class="s0">import </span><span
        class="s1">android.content.Context;
<a name="l4"><span class="ln">4    </span></a></span><span class="s0">import </span><span
        class="s1">android.content.SharedPreferences;
<a name="l5"><span class="ln">5    </span></a> 
<a name="l6"><span class="ln">6    </span></a></span><span class="s2">/** 
<a name="l7"><span class="ln">7    </span></a> * Created by Girishn on 08-05-2014. 
<a name="l8"><span class="ln">8    </span></a> */</span><span class="s1"> 
<a name="l9"><span class="ln">9    </span></a></span><span class="s0">public class </span><span
        class="s1">Utilty {
<a name="l10"><span class="ln">10   </span></a> 
<a name="l11"><span class="ln">11   </span></a>    </span><span
        class="s0">public static final </span><span class="s1">String PREFS_NAME = </span><span
        class="s3">&quot;IBR_PPrefsStorage&quot;</span><span class="s1">;
<a name="l12"><span class="ln">12   </span></a>    </span><span
        class="s0">public static final </span><span class="s1">String PREFS_VARIABLE_TOKEN = </span><span
        class="s3">&quot;token&quot;</span><span class="s1">;
<a name="l13"><span class="ln">13   </span></a>    </span><span
        class="s0">private static </span><span class="s1">String token = </span><span class="s3">&quot;&quot;</span><span
        class="s1">;
<a name="l14"><span class="ln">14   </span></a> 
<a name="l15"><span class="ln">15   </span></a>    </span><span
        class="s0">public static void </span><span class="s1">setToken(String token) {
<a name="l16"><span class="ln">16   </span></a>        Utilty.token = token; 
<a name="l17"><span class="ln">17   </span></a>    } 
<a name="l18"><span class="ln">18   </span></a> 
<a name="l19"><span class="ln">19   </span></a>    </span><span
        class="s0">public static boolean </span><span class="s1">isLoggedIn(Context context) {
<a name="l20"><span class="ln">20   </span></a>        </span><span class="s0">if </span><span
        class="s1">(token == </span><span class="s0">null </span><span class="s1">|| </span><span
        class="s3">&quot;&quot;</span><span class="s1">.equals(token)) {
<a name="l21"><span class="ln">21   </span></a>            SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, </span><span
        class="s4">0</span><span class="s1">);
<a name="l22"><span class="ln">22   </span></a>            setToken(settings.getString(PREFS_VARIABLE_TOKEN, </span><span
        class="s3">&quot;&quot;</span><span class="s1">));
<a name="l23"><span class="ln">23   </span></a>        } 
<a name="l24"><span class="ln">24   </span></a>        </span><span class="s0">return </span><span
        class="s1">(</span><span class="s0">null </span><span
        class="s1">!= token &amp;&amp; !</span><span class="s3">&quot;&quot;</span><span class="s1">.equals(token));
<a name="l25"><span class="ln">25   </span></a>    } 
<a name="l26"><span class="ln">26   </span></a> 
<a name="l27"><span class="ln">27   </span></a>    </span><span
        class="s0">public static void </span><span class="s1">setLoginToken(Context context, String token) {
<a name="l28"><span class="ln">28   </span></a>        SharedPreferences settings = context.getSharedPreferences(PREFS_NAME, </span><span
        class="s4">0</span><span class="s1">);
<a name="l29"><span class="ln">29   </span></a>        SharedPreferences.Editor editor = settings.edit(); 
<a name="l30"><span class="ln">30   </span></a>        editor.putString(PREFS_VARIABLE_TOKEN, token); 
<a name="l31"><span class="ln">31   </span></a> 
<a name="l32"><span class="ln">32   </span></a>        </span><span
        class="s2">// Commit the edits!</span><span class="s1">
<a name="l33"><span class="ln">33   </span></a>        editor.commit(); 
<a name="l34"><span class="ln">34   </span></a>         
<a name="l35"><span class="ln">35   </span></a>        </span><span
        class="s2">//Set in variable</span><span class="s1">
<a name="l36"><span class="ln">36   </span></a>        isLoggedIn(context); 
<a name="l37"><span class="ln">37   </span></a>    } 
<a name="l38"><span class="ln">38   </span></a>} 
<a name="l39"><span class="ln">39   </span></a></span></pre>
</body>
</html>